<html>
<head>
	<meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>学生登录</title>
    <link rel="stylesheet" href="./css/stuLogin.css">
    <script src="./js/jquery-3.2.1.min.js"></script>
    <script src="./js/stuLogin.js"></script>
</head>
<body>
<script type="text/javascript">
	//var message = '<%=request.getAttribute("message")%>';
	//if(message != 'null'){
		//alert(message);
	//}
</script>
    <div id="body1">
        <div class="left">
            <div id="lb1"><img width="100%" height="auto" src="./images/1.jpg" alt=""></div>
            <div id="lb2"><img width="100%" height="auto" src="./images/2.jpg" alt=""></div>
            <div id="lb3"><img width="100%" height="auto" src="./images/3.jpg" alt=""></div>
            <div id="lb4"><img width="100%" height="auto" src="./images/4.jpg" alt=""></div>

            <div class="btn">
                <div id="btn1"></div>
                <div id="btn2"></div>
                <div id="btn3"></div>
                <div id="btn4" style="margin-right: 0"></div>
            </div>
        </div>
        <form id="loginff" onsubmit="return check()">
            <div id="loginf">
                <div id="message">请输入学号和密码</div>
                
                <div class="div1">
                    <img src="./images/userName.png" alt="">
                    <input class="input1" type="text" name="account" id="account">
                </div>
                <div class="div1">
                    <img src="./images/password.png" alt="">
                    <input class="input1" type="password" name="password" id="password">
                </div>
                
                <div class="div1" style="display: none">
                    <img src="./images/yzm.png" alt="" >
                    <input type="text" name="yzm" id="yzm" class="input1" autocomplete="off">
                </div>
                <div class="div2" >
                    <img style="width:120px;height:30px;display: none"  alt="验证码丢失了" src="./GetCodeServlet.do?action=getCode" id="yzmPic">
                    <input type="button" id="login" class="btn2" value="LOGIN">
                </div>
            </div>
        </form>
    </div>
</body>
<script type="text/javascript">

$(document).ready(function(){ 
	$("#login").click(function(){
		if($("#account").val()==''){
			alert("请输入用户名！")
		}else{
		$.ajax({
			type:"post",//请求类型
			url:"/EDUSystem/account/Login.do",//请求路径
			dataType:"json",//响应的数据类型
			data:$("#loginff").serialize(),
			success:function suc(dt){//响应成功后的回调函数
				if (dt.code == 1) {
					a=false;
					alert("该用户是学生教师，请跳转到教师登录界面进行登录！")
				}else if(dt.code==2){
					a=true;
					location.href="stu/index.html"
				}else if (dt.code == 0) {
					a=false;
					alert("该用户是管理员用户，请跳转到管理员登录界面进行登录！")
				}else{
					alert(dt.message)
				}
			},
			error:function err(){
				alert("服务器出现故障")
			}
		});
		}
	});
	$("#account").blur(function(){
		if($("#account").val()==''){
			alert("请输入用户名！")
		}else{
			$.post({
				type:"post",//请求类型
				url:"/EDUSystem/account/checkAccount.do",//请求路径
				dataType:"json",//响应的数据类型
				data:$("#loginff").serialize(),
				success:function suc(dt){//响应成功后的回调函数
					if (dt.code == 0) {
						a=false;
						alert("该用户是管理员用户，请跳转到管理员登录界面进行登录！")
					}else if(dt.code==2){
						a=true;
					}else if(dt.code==1){
						a=false;
						alert("该用户是学生教师，请跳转到教师登录界面进行登录！")
						
					}else{
						alert(dt.message)
					}
				},
				errer:function err(){
					alert("服务器出现故障")
				}
			});
		}
		
	});
});
var a=false;
function check(){
	if(a==false){
	    return false;
	}else{
	    return true;
	}
}
</script>
</html>